/*
 * Copyright 2006 Robert Burrell Donkin
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 * you may not use this file except in compliance with the License.
 * You may obtain a copy of the License at
 * 
 *      http://www.apache.org/licenses/LICENSE-2.0
 * 
 * Unless required by applicable law or agreed to in writing, software
 * distributed under the License is distributed on an "AS IS" BASIS,
 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 * See the License for the specific language governing permissions and
 * limitations under the License.
 */ 
package rat;

import rat.license.ILicense;
import rat.license.standard.IStandardLicenseVisitor;
import rat.license.util.LicenseUtils;

/**
 * Collects information used in summary.
 *
 */
public class SummaryVisitor extends ElementVisitorImpl implements Reportable {
    
    private int noteCount = 0;
    private int binaryCount = 0;
    private int archiveCount = 0;
    private int standardCount = 0;
    
    private final IStandardLicenseVisitor visitor;
    
    /**
     * Constructs a summary visitor.
     * @param visitor <code>IStandardLicenseVisitor</code> to visit the standard elements, 
     * otherwise null
     */
    public SummaryVisitor(final IStandardLicenseVisitor visitor) {
        this.visitor = visitor;
    }
    
    public int getNoteCount() {
        return noteCount;
    }

    public int getArchiveCount() {
        return archiveCount;
    }

    public int getBinaryCount() {
        return binaryCount;
    }

    public int getStandardCount() {
        return standardCount;
    }

    public void visit(NoteElement note) {
        noteCount++;
    }

    public void visit(BinaryElement binary) {
        binaryCount++;
    }

    public void visit(ArchiveElement archive) {
        archiveCount++;
    }

    public void visit(final StandardContentElement standardContent) {
        standardCount++;
        if (visitor != null) {
            final ILicense license = standardContent.getLicense();
            LicenseUtils.visit(license, visitor);
        } 
    }
    
    public void report(final IPrinter printer) {
        printer.printLine("Notes:    " + noteCount);
        printer.printLine("Binaries: " + binaryCount);
        printer.printLine("Archives: " + archiveCount);
        printer.printLine("Standards: " + standardCount);
        if (visitor != null && visitor instanceof Reportable) {
            Reportable reportableVisitor = (Reportable) visitor;
            reportableVisitor.report(printer);
        }
    }
}
